<?php
// +----------------------------------------------------------------------
// | OneKeyAdmin [ Believe that you can do better ]
// +----------------------------------------------------------------------
// | Copyright (c) 2020-2023 http://onekeyadmin.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: MUKE <513038996@qq.com>
// +----------------------------------------------------------------------
namespace plugins\cms\index\listen;

use think\facade\View;
use plugins\cms\index\model\Banner;

class RouteLoaded
{
    public function handle()
    {
        $banner  = [];
        $catalog = request()->catalog;
        if (! empty($catalog['id'])) {
            $where[] = ['status', '=', 1];
            $where[] = ['catalog_id', 'find in set', $catalog['id']];
            $order  = ['sort' => 'desc', 'id' => 'desc'];
            $field  = 'cover,title,c_title,description,url,content';
            $show   = request()->isMobile() ? 2 : 1;
            $banner = Banner::where($where)->where('show',0)->whereOr('show', $show)->field($field)->order($order)->select()->toArray();
        }
        View::assign([
            'banner' => $banner
        ]);
    }   
}